
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>请求http · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../project/" />
    
    
    <link rel="prev" href="../form/" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../Angular-cli/">
            
                <a href="../Angular-cli/">
            
                    
                    Angular-cli
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../Angular-cli/Angular-cli.html">
            
                <a href="../Angular-cli/Angular-cli.html">
            
                    
                    安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../Angular-cli/restMenu.html">
            
                <a href="../Angular-cli/restMenu.html">
            
                    
                    初始结构
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../architecture/">
            
                <a href="../architecture/">
            
                    
                    架构
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="../architecture/mo-kuai.html">
            
                <a href="../architecture/mo-kuai.html">
            
                    
                    模块简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="../architecture/component.html">
            
                <a href="../architecture/component.html">
            
                    
                    组件简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="../architecture/Service.html">
            
                <a href="../architecture/Service.html">
            
                    
                    服务与依赖注入
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../comAndtem/">
            
                <a href="../comAndtem/">
            
                    
                    组件与模板
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../comAndtem/zu-jian-yu-mo-ban.html">
            
                <a href="../comAndtem/zu-jian-yu-mo-ban.html">
            
                    
                    数据显示与模板语法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../comAndtem/cycle.html">
            
                <a href="../comAndtem/cycle.html">
            
                    
                    生命周期钩子
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../comAndtem/component.html">
            
                <a href="../comAndtem/component.html">
            
                    
                    组件交互
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../comAndtem/style.html">
            
                <a href="../comAndtem/style.html">
            
                    
                    组件样式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../comAndtem/dynamic.html">
            
                <a href="../comAndtem/dynamic.html">
            
                    
                    动态组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../comAndtem/directive.html">
            
                <a href="../comAndtem/directive.html">
            
                    
                    属性指令与结构指令
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../comAndtem/pipeAndAnimit.html">
            
                <a href="../comAndtem/pipeAndAnimit.html">
            
                    
                    管道与动画
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../router/">
            
                <a href="../router/">
            
                    
                    路由与导航
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../form/">
            
                <a href="../form/">
            
                    
                    表单
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.7" data-path="./">
            
                <a href="./">
            
                    
                    请求http
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../project/">
            
                <a href="../project/">
            
                    
                    项目解析:结构目录
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >请求http</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <ul>
<li>&#x5F15;&#x5165; http</li>
</ul>
<p><img src="../assets/http.png" alt=""></p>
<ul>
<li>&#x4F9D;&#x8D56;&#x6CE8;&#x5165;</li>
</ul>
<p><img src="../assets/http2.png" alt=""></p>
<ul>
<li>&#x8BF7;&#x6C42;&#x5934;&#x7684;&#x8BBE;&#x7F6E; &#x4EE5;&#x53CA;&#x9875;&#x9762;loading&#x52A0;&#x8F7D;</li>
</ul>
<pre><code>    getRequestOptionsArgs() {
        let header = new Headers();
        header.append(&apos;X-Requested-With&apos;, &apos;XMLHttpRequest&apos;);
        header.append(&apos;Authorization&apos;, `Bearer ${this.taken()}`);
        let option: RequestOptionsArgs = { headers: header };
        return option;
  }
</code></pre><ul>
<li>get post &#x91CD;&#x5199; </li>
</ul>
<pre><code>        /**
    * http get&#x91CD;&#x5199;
    */
    async get(url: string, option?: RequestOptionsArgs) {
        await this.validtimeout();
        if (!option) option = { params: { ts: new Date().getTime() } };
        option.withCredentials = true;
        Object.assign(option, this.getRequestOptionsArgs());
        this.block.blockUI(); 
        const result = await this.http.get(this.domain + url, option).toPromise().then(res =&gt; {
        return this.HandSuccessResult(res);
        }).catch(async res =&gt; {
        await this.HandErrorResult(res);
        });
        this.lastdate = new Date();
        return result;
    }

    /**
    * http post&#x91CD;&#x5199;
    */
    async post(url: string, body?: any, option?: RequestOptionsArgs) {
        await this.validtimeout();
        if (!option) option = {};

        option.withCredentials = true;
        Object.assign(option, this.getRequestOptionsArgs());

        if (body &amp;&amp; Object.prototype.toString.call(body) === &quot;[object Object]&quot;) {
        body = format_object(body);
        }
        this.block.blockUI();
        const result = await this.http.post(this.domain + url, body, option).toPromise().then(res =&gt; {
        return this.HandSuccessResult(res);
        }).catch(async res =&gt; {
        await this.HandErrorResult(res);
        });
        this.lastdate = new Date();
        return result;
    }
</code></pre><ul>
<li>&#x5904;&#x7406; &#x6B63;&#x786E;&#x548C;&#x9519;&#x8BEF;&#x8BF7;&#x6C42;</li>
</ul>
<pre><code>        /**
    * &#x5904;&#x7406;http&#x6B63;&#x786E;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;
    */
    HandSuccessResult(res: Response) {
        let httpresult = res.json();
        if (httpresult.result) {
        this.block.UnBlockUI();
        if (httpresult.data) {
            return httpresult.data;
        } else {
            return true;
        }
        }
        else {
        // this.mydialog.openMessage(httpresult.message, &quot;&#x64CD;&#x4F5C;&#x5931;&#x8D25;&quot;, &quot;error&quot;);
        throw res;
        }
    }

    /**
    * &#x5904;&#x7406;http&#x9519;&#x8BEF;&#x6B63;&#x786E;&#x8FD4;&#x56DE;&#x7ED3;&#x679C;
    */
    async HandErrorResult(res: Response) {
        if (res.status == 401) {
        this.block.UnBlockUI();
        await this.route.navigateByUrl(&apos;login&apos;);
        throw res;
        }
        this.block.UnBlockUI();
        if (res.ok) {
        let result = res.json();
        this.ds.Error(result.message || &apos;&#x62B1;&#x6B49;,&#x65E0;&#x4EFB;&#x4F55;&#x9519;&#x8BEF;&#x4FE1;&#x606F;&#x8FD4;&#x56DE;!&apos;);
        }
        else {
        if (res.status == 403) {
            this.ds.Error(&apos;&#x60A8;&#x6CA1;&#x6709;&#x8BBF;&#x95EE;&#x6743;&#x9650;!&apos;);
        }
        else if (res.status &lt; 200 || res.status &gt; 290) {
            this.ds.Error(res.statusText || &apos;&#x7F51;&#x7EDC;&#x5F02;&#x5E38;!&apos;);
        }
        }
        throw res;
    }
</code></pre><ul>
<li>&#x4F7F;&#x7528; </li>
</ul>
<p><img src="../assets/http4.png" alt=""></p>
<p>ebvironment.ts  &#x4E3A;&#x9879;&#x76EE;&#x4F9D;&#x8D56;&#x5F00;&#x53D1;&#x6D4B;&#x8BD5;
ebvironment.prod.ts  &#x4E3A;&#x9879;&#x76EE;&#x7EBF;&#x4E0A;&#x90E8;&#x7F72;&#x73AF;&#x5883;</p>
<p>&#x5148;&#x5F15;&#x5165;&#x4E0A;&#x4E0A;&#x6B65;&#x9AA4;&#x5EFA;&#x597D;&#x7684; http.server &#x4EE5;&#x53CA;&#x5176;&#x4ED6;&#x670D;&#x52A1;</p>
<pre><code>    import { Injectable } from &apos;@angular/core&apos;;
    import { RequestOptionsArgs } from &apos;@angular/http&apos;;
    import { HttpService } from &apos;../app/service/http.service&apos;;
    import { DomHelperService } from &apos;../app/service/dom-helper.service&apos;;
</code></pre><p>&#x58F0;&#x660E;&#x6B64;&#x670D;&#x52A1;&#x4E3A;API &#x670D;&#x52A1;</p>
<pre><code>    @Injectable()
    export class ApiService {
    dynamic = true;
    // /BaseService = &apos;/Base&apos;;  //&#x57FA;&#x7840;&#x670D;&#x52A1;
    // BidService = &apos;/bid&apos;;  // &#x62A2;&#x5355;&#x670D;&#x52A1;
    // DrawService = &apos;/draw&apos;;  // &#x56FE;&#x7EB8;&#x670D;&#x52A1;
    // DecorationService = &apos;/decoration&apos;;   // &#x88C5;&#x4FEE;&#x670D;&#x52A1;
    // SalaryService = &apos;/salary&apos;;     // &#x7ED3;&#x7B97;&#x670D;&#x52A1;

    // Employee=&quot;/employee&quot;;//&#x4EBA;&#x5458;&#x7BA1;&#x7406;

    constructor(private http: HttpService,
        private dom: DomHelperService) {
    }
    }
</code></pre><p>&#x63A5;&#x53E3;&#x4E66;&#x5199;</p>
<pre><code>    Account = this.dynamic ? {  // Account &#x4E3A;&#x63A5;&#x53E3;&#x670D;&#x52A1;&#x540D;
        LoginBycommon: (option) =&gt; this.http.post(&apos;/identityserver/account/LoginBycommon&apos;, option),
        logout: () =&gt; this.http.post(&apos;/identityserver/account/logout&apos;),
        revisePwd: (option) =&gt; this.http.post(`/Base/api/User/UpdatePasswordByOldPasApp`, option),
        VerifyImage: &apos;/identityserver/account/VerifyImage&apos;,
        GetValidCode: () =&gt; this.http.get(&apos;/identityserver/account/GetValidCode&apos;)
    }
        : {
        LoginBycommon: (option) =&gt; this.http.get(&apos;/assets/json/info.getEmployeeList.json&apos;),
        logout: () =&gt; this.http.post(&apos;/identityserver/account/logout&apos;),
        revisePwd: (option) =&gt; this.http.post(`/Base/api/User/UpdatePasswordByOldPasApp`, option),
        VerifyImage: &apos;/identityserver/account/VerifyImage&apos;,
        GetValidCode: () =&gt; this.http.get(&apos;/identityserver/account/GetValidCode&apos;)
        };
</code></pre><p>dynamic &#x4E3A; true &#x65F6;  &#x83B7;&#x53D6;&#x7EBF;&#x4E0A;&#x6D4B;&#x8BD5;
dynamic &#x4E3A; false &#x65F6;  &#x83B7;&#x53D6;&#x524D;&#x671F;&#x5F00;&#x53D1;&#x6A21;&#x62DF;&#x7684;&#x6570;&#x636E;</p>
<p>ebvironment.prod.ts &#x6587;&#x4EF6;&#x53EA;&#x83B7;&#x53D6;&#x7EBF;&#x4E0A;&#x6570;&#x636E; </p>
<pre><code>     Account = {
        LoginBycommon: (option) =&gt; this.http.post(&apos;/identityserver/account/LoginBycommon&apos;, option),
        logout: () =&gt; this.http.post(&apos;/identityserver/account/logout&apos;),
        revisePwd: (option) =&gt; this.http.post(`/Base/api/User/UpdatePasswordByOldPasApp`, option),
        VerifyImage: &apos;/identityserver/account/VerifyImage&apos;,
        GetValidCode: () =&gt; this.http.get(&apos;/identityserver/account/GetValidCode&apos;)
    };
</code></pre><p>&#x7EC4;&#x4EF6;&#x83B7;&#x53D6;&#x6570;&#x636E;</p>
<p>&#x6CE8;&#x5165; api&#x670D;&#x52A1;</p>
<pre><code>constructor(
              private api: ApiService) {

  }
    // &#x53D1;&#x9001;&#x8BF7;&#x6C42;
    this.api.ReportDecoration.GetTraceResultList(this.searchOption).then(data =&gt; {
      this.groups = data
    });
</code></pre>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="../form/" class="navigation navigation-prev " aria-label="Previous page: 表单">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../project/" class="navigation navigation-next " aria-label="Next page: 项目解析:结构目录">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"请求http","level":"1.7","depth":1,"next":{"title":"项目解析:结构目录","level":"1.8","depth":1,"path":"project/README.md","ref":"project/README.md","articles":[]},"previous":{"title":"表单","level":"1.6","depth":1,"path":"form/README.md","ref":"form/README.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["fontsettings","sharing","lunr","search","highlight","livereload"],"pluginsConfig":{"fontsettings":{"family":"sans","size":2,"theme":"white"},"sharing":{"all":["facebook","google","twitter","weibo","instapaper"],"facebook":true,"google":false,"instapaper":false,"twitter":true,"vk":false,"weibo":false},"lunr":{"ignoreSpecialCharacters":false,"maxIndexSize":1000000},"search":{},"highlight":{},"livereload":{},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"http/README.md","mtime":"2018-06-20T06:05:00.205Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2018-06-29T06:02:19.129Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    

    </body>
</html>

